package es

import (
	"gitee.com/mootok/mootok/src/constant/config"
	"gitee.com/mootok/mootok/src/utils/logging"
	es "github.com/elastic/go-elasticsearch/v7"
)

var Client *es.Client

var VideoStore *Store

const VideoMapping = `{
    "mappings": {
		"properties": {
			"id": {
				"type": "keyword"
			},
			"user_id": {
				"type": "keyword"
			},
			"description": {
				"type": "text",
				"analyzer": "ik_max_word",
				"search_analyzer": "ik_smart"
			},
			"keywords": {
				"type": "keyword"
			},
			"created_at": {
				"type": "date"
			},
			"updated_at": {
				"type": "date"
			}
		}
    }
}`

func init() {
	logger := logging.LogService("EsClient.Init")
	cfg := es.Config{
		Addresses: []string{
			config.EnvConfig.ElasticsearchUrl,
		},
	}
	var err error
	Client, err = es.NewClient(cfg)
	if err != nil {
		logger.Fatalf("elasticsearch.NewClient: %v", err)
	}

	_, err = Client.Info()
	if err != nil {
		logger.Fatalf("Error getting response: %s", err)
	}

	VideoStore = NewStore(StoreConfig{Client: Client, IndexName: "videos"})
}
